<html>

<head>
    <meta charset="utf-8">
    <title>新增礼物</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/${BasePath}/static/css/headpic.css" media="all" />
    <link rel="stylesheet" href="/${BasePath}/static/layui/css/layui.css" media="all" type="text/css">
    <link rel="stylesheet" href="/${BasePath}/static/css/public.css" media="all" type="text/css"> </head>

<body class="childrenBody">
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
	  <legend>新增礼物</legend>
	</fieldset>
    <form id="giftForm" class="layui-form" lay-filter="example">
    <input type="hidden" name="id" id="id" value="${gift.id!'0'}">
    <input type="hidden" name="giftpic" id="giftpic" value="${gift.giftpic!'/${BasePath}/static/images/userface4.jpg'}">
        <div class="layui-col-md6 layui-col-xs12">
            <div class="layui-form-item">
                <label class="layui-form-label">礼物</label>
                <div class="layui-input-block"> 
                	<a class="img" title="礼物设置" ><img id="upload" class="shop-logo" alt="点击上传" src="${gift.giftpic!'/${BasePath}/static/images/userface4.jpg'}"></a>
                    <input id="upfile" style="display: none" type="file" name="upfile"> 
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-block">
                    <input type="text" name="price" lay-verify="required|number" value="${gift.price!''}" placeholder="请输入价格" class="layui-input realName"> </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">票数</label>
                <div class="layui-input-block">
                    <input type="tel" name="votenum" lay-verify="required|number" value="${gift.votenum!''}" placeholder="请输入票数" class="layui-input realName"> </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" type="button" lay-filter="form">立即提交</button>
                </div>
            </div>
        </div>
    </form>
    <script type="text/javascript" src="/${BasePath}/static/layui/layui.js" charset="utf-8" ></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/ajaxfileupload.js" charset="utf-8" ></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/popup.js"></script>
    <script type="text/javascript">
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;
        form.on('submit(form)', function() {
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/${BasePath}/gift/saveGift",
                    data: $('#giftForm').serialize(),
                    async: false,
                    error: function(request) {
                        layer.msg('系统错误！');
                    },
                    success: function(data) {
                        if(data.code = "1") {
                            layer.msg(data.msg, {
                                time: 1000
                            }, function() { //提示框设定显示1秒
                                location.reload();
                            })
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                });
            })
    });
    /* 上传图片 */
    $("#upload").on('click', function() {
        $("#upfile").click();
    });
    $("#upfile").on("change", upfile);

    function upfile() {
        var fileSize = $("#upfile")[0].files[0].size;//文件的大小，单位为字节B
        if(fileSize > 1048576) {
            showTips('请上传大小小于1M的图片');  
        }else{
            $.ajaxFileUpload({
                secureuri: false,
                url: "/${BasePath}/upload/springUpload",
                dataType: "json",
                //fileElementId是img标签的id  
                fileElementId: 'upfile',
                success: function(data) {
                    //上传成功后改变<img>标签的src地址，id参数其实不需要，主要是为了刷新img的图片资源。  
                    $("#upload").attr("src", data.path);
                    $("#giftpic").val(data.path);
                    //重新绑定事件，防止二次上传时失效  
                    $("#upfile").on("change", upfile);
                }
            });        	
        }
    }
    </script>
</body>

</html>